/**
 * Created With IntelliJ IDEA
 * Description:leetcode：912. 排序数组（包含各种排序算法）
 * <a href="https://leetcode.cn/problems/sort-an-array/">...</a>
 * User: DELL
 * Data: 2023-01-27
 * Time: 22:27
 */
public class Solution {
    /**
     * 冒泡排序
     */
    public int[] sortArray(int[] nums) {
        int len = nums.length;
        for (int i = 0; i < len; i++) {
            for (int j = 0; j < len - i; j++) {
                if (nums[j] > nums[j+1]) {
                    int temp = nums[j];
                    nums[j] = nums[j+1];
                    nums[j+1] = temp;
                }
            }
        }
        return nums;
    }
    /**
     * 选择排序
     */
    public int[] sortArray2(int[] nums) {
        int len = nums.length;
        int minIndex = 0;
        for (int i = 0; i < len - 1; i++) {
            for (int j = i+1; j < len; j++) {
                if (nums[minIndex] > nums[j]) {
                    minIndex = j;
                }
            }
            int temp = nums[minIndex];
            nums[minIndex] = nums[i];
            nums[i] = temp;
            minIndex = i + 1;
        }
        return nums;
    }
}